package com.rectcircle.wechat.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 
 * 常量类，读取配置文件信息。
 * 
 * @author RectCircle
 * @version 0.1<br>
 * 2016年7月13日-下午6:19:24<br>
 * Copyright (c) 2016 RectCircle-版权所有<br>
 *
 */
public class Constants {
	//private static final String returnCodeFile =Constants.class.getResource("/").getPath() + "ReturnCode.properties";
	private static final InputStream returnCodeFile =Constants.class.getResourceAsStream("/ReturnCode.properties");
	//private static final String apiFile =Constants.class.getResource("/").getPath() + "api.properties";
	private static final InputStream apiFile =Constants.class.getResourceAsStream("/api.properties");
	private static final Properties returnCodeProp = new Properties();
	private static final Properties apiProp = new Properties();
	private static String token;
	private static String appid;
	private static String appsecret;

	public static String getAppid() {
		return appid;
	}

	public static void setAppid(String appid) {
		Constants.appid = appid;
	}

	public static String getAppsecret() {
		return appsecret;
	}

	public static void setAppsecret(String appsecret) {
		Constants.appsecret = appsecret;
	}

	public static String getToken() {
		return token;
	}

	public static void setToken(String token) {
		Constants.token = token;
	}

	static{
		try {
			//returnCodeProp.load(new java.io.FileInputStream(returnCodeFile));
			returnCodeProp.load(returnCodeFile);
			//apiProp.load(new java.io.FileInputStream(apiFile));
			apiProp.load(apiFile);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 获得微信api的url参数为%s的字符串
	 * @param key
	 * @return 
	 */
	public static String getApi(String key){
		return apiProp.getProperty(key);
	}

	/**
	 * 获取微信全局返回码对应的中文描述
	 * 
	 * @param key
	 * @return
	 */
	public static String getRetMsgByCode(String key){
		return returnCodeProp.getProperty(key);
	}
	
}
